﻿/*
Author: Aaron
Date: 2015-05-30
Description: 首页动态加载数据
*/

$(function () {
    $(".worktab li").click(function () {

        if ($(this).find("a").hasClass('cur')) {
            return;
        }

        $(".worktab li").find("a").removeClass("cur");
        $(this).find("a").addClass("cur");
        var ind = $(".worktab li").index($(this));
        $(".worktabcon").addClass("f-hide");
        $(".tasktab li").parents(".g-main").find(".worktabcon").eq(ind).removeClass("f-hide");

        change_top_tab($(this).find("a").attr('ID'));
    });

    $(".tasktab li").click(function () {
        $(".tasktab li").find("a").removeClass("cur");
        $(this).find("a").addClass("cur");
        var ind = $(".tasktab li").index($(this));
        $(".mytask").addClass("f-hide");
        $(".tasktab li").parents(".mytasklist").find(".mytask").eq(ind).removeClass("f-hide");
    });

    change_top_tab('uncompleted');
});

/*
Ajax 获取 最新动态列表、我的任务列表
*/
function change_top_tab(key) {
    switch (key) {
        case 'my_feed':

            break;
        case 'my_task':
            change_top_tab('uncompleted');
            break;
        case 'uncompleted':
            var tpl = [
                ' <div class="task-list-panel">',
                ' <div class="group-list">',
                '{@each data as it, k}',
                '<div class="group-item">',
                //'<div class="group-header"> <span class="ng-binding">已过期</span> <span class="badge ml_20 ng-binding">1</span> </div>',
                ' <div class="group-task-item slide-trigger f-clear">',
                '<div class="task-main"> <a href="javascript:;" class="task-check"> <i class="icon-check-empty"></i> </a> <span class="task-title ng-binding">${it.TaskDesc}</span> </div>',
               // '<div class="task-badges"><span class="task-badge icon icon-time badge-expire-due" title="任务已经截止">02-10</span> <span class="task-badge icon icon-desktop icon-project-name" title="熟悉 Worktile">熟悉 Worktile</span> </div>',
                //'<div class="task-members"><a class="mr_5 avatar avatar-30" member="member" size="30" title="梅郑冬" href="javascript:;"> <span class="avatar-face"><span class="avatar-text">梅</span></span> </a></div>',
                '</div>',
               '</div>',
				'{@/each}',
                '</div>',
                '</div>'
            ].join('\n');

            ajaxPost('/App/GetUncompleted', function (d) {
                var str = juicer(tpl, d);
                $("#uncompleted").html(str);
            });
            break;
        case 'completed':
            var tpl = [
                   ' <div class="task-list-panel">',
                   ' <div class="group-list">',
                   '{@each data as it, k}',
                   '<div class="group-item">',
                   //'<div class="group-header"> <span class="ng-binding">已过期</span> <span class="badge ml_20 ng-binding">1</span> </div>',
                   ' <div class="group-task-item slide-trigger f-clear">',
                   '<div class="task-main"> <a href="javascript:;" class="task-check"> <i class="icon-check-empty"></i> </a> <span class="task-title ng-binding">${it.TaskDesc}</span> </div>',
                  // '<div class="task-badges"><span class="task-badge icon icon-time badge-expire-due" title="任务已经截止">02-10</span> <span class="task-badge icon icon-desktop icon-project-name" title="熟悉 Worktile">熟悉 Worktile</span> </div>',
                   //'<div class="task-members"><a class="mr_5 avatar avatar-30" member="member" size="30" title="梅郑冬" href="javascript:;"> <span class="avatar-face"><span class="avatar-text">梅</span></span> </a></div>',
                   '</div>',
                  '</div>',
                   '{@/each}',
                   '</div>',
                   '</div>'
            ].join('\n');

            ajaxPost('/App/GetCompleted', function (d) {
                var str = juicer(tpl, d);
                $("#completed").html(str);
            });
            break;
        case 'expired':
            var tpl = [
             ' <div class="task-list-panel">',
             ' <div class="group-list">',
             '{@each data as it, k}',
             '<div class="group-item">',
             //'<div class="group-header"> <span class="ng-binding">已过期</span> <span class="badge ml_20 ng-binding">1</span> </div>',
             ' <div class="group-task-item slide-trigger f-clear">',
             '<div class="task-main"> <a href="javascript:;" class="task-check"> <i class="icon-check-empty"></i> </a> <span class="task-title ng-binding">${it.TaskDesc}</span> </div>',
            // '<div class="task-badges"><span class="task-badge icon icon-time badge-expire-due" title="任务已经截止">02-10</span> <span class="task-badge icon icon-desktop icon-project-name" title="熟悉 Worktile">熟悉 Worktile</span> </div>',
             //'<div class="task-members"><a class="mr_5 avatar avatar-30" member="member" size="30" title="梅郑冬" href="javascript:;"> <span class="avatar-face"><span class="avatar-text">梅</span></span> </a></div>',
             '</div>',
            '</div>',
             '{@/each}',
             '</div>',
             '</div>'
            ].join('\n');

            ajaxPost('/App/GetExpired', function (d) {
                var str = juicer(tpl, d);
                $("#expired").html(str);
            });
            break;
        default:
    }
}

